<?php

require_once dirname(__FILE__).'/../model/ManagersModel.class.php';
class ManagerController{
	
	//显示所有选课信息
	public function showAllCourses(){
		//调用下层函数
		$managerModel = new ManagersModel();
		$showAllCoursesInfo = $managerModel->showAllCourses();
		return $showAllCoursesInfo;
	}
	
	//删除课程信息
	public function deleteCourse($courseId){
		$managerModel = new ManagersModel();
		$managerModel->deleteCourse($courseId);
	}
	
	
	//显示单项课程信息
	public function showSimpleCourse($courseId){
		$managerModel = new ManagersModel();
		$showSimpleInfo = $managerModel->showSimpleCourse($courseId);
		return $showSimpleInfo;
	}
	
	//修改课程信息
	public function reviseCourses($courseId,$courseName,$courseTeacher,$courseMaxCount){

		$managerModel = new ManagersModel();
		//修改
		$managerModel->reviseCourse($courseId, $courseName, $courseTeacher, $courseMaxCount);
	}
	
	//新增课程信息
	public function addCourse($courseId, $courseName, $courseTeacher, $courseMaxCount){
		$managerModel = new ManagersModel();
		//新增
		return $managerModel->addCourse($courseId, $courseName, $courseTeacher, $courseMaxCount);
	}
	
}
	//获取操作细节
	$operation = isset($_GET['operation']) ? $_GET['operation'] : "";
	$object = isset($_GET['object']) ? $_GET['object'] : "";
	$courseId = isset($_GET['courseId']) ? $_GET['courseId'] : "";
	
	$managerController = new ManagerController();
	//修改课程
	if($operation === 'revise' && $object === 'course' && $courseId === 'sure'){
		//获取参数
	 	$courseId1 = isset($_POST['courseId1']) ? $_POST['courseId1'] : "";
		$courseName =isset($_POST['courseName']) ? $_POST['courseName'] : "";
		$courseTeacher = isset($_POST['courseTeacher']) ? $_POST['courseTeacher'] : "";
		$courseMaxCount = isset($_POST['courseMaxCount']) ? $_POST['courseMaxCount'] : "";
		//执行修改
		if($courseId1!=null && $courseName!=null && $courseTeacher!= null && $courseMaxCount!=null){
			//执行修改
			$managerController->reviseCourses($courseId1, $courseName, $courseTeacher, $courseMaxCount);
			header("Location:http://localhost/SelectCoursesSystem/view/manager/ManagerView.php");
		} else {
			//回到主界面
			header("Location:http://localhost/SelectCoursesSystem/view/manager/ManagerView.php");
		} 		
	} else if($operation === 'addcourse' && $object === 'course' && $courseId === 'sure'){
		//添加课程
		//获取参数
		$courseId = isset($_POST['courseId']) ? $_POST['courseId'] : "";
		$courseName = isset($_POST['courseName']) ? $_POST['courseName'] : "";
		$courseTeacher = isset($_POST['courseTeacher']) ? $_POST['courseTeacher'] : "";
		$courseMaxCount = isset($_POST['courseMaxCount']) ? $_POST['courseMaxCount'] : "";
		//执行新增
		$canAddInfo = $managerController->addCourse($courseId, $courseName, $courseTeacher, $courseMaxCount);
		//表示课程编号已经存在
		if($canAddInfo === 'false'){
			//回到主界面
		}
			header("Location:http://localhost/SelectCoursesSystem/view/manager/ManagerView.php");
	}
	
	//提交修改课程表单
	//header("Location:http://localhost/SelectCoursesSystem/view/manager/ManagerView.php");
?>